package com.jld.mybatis.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class SqlSessionUtil {
   public static SqlSession getSqlSession() throws IOException {
       InputStream resourceAsStream = Resources.getResourceAsStream("mybatis-config.xml");
       SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
       SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(resourceAsStream);
       SqlSession sqlSession = sqlSessionFactory.openSession(true);
       return sqlSession;
   }
}
